package com.example.reagent_management.room.entity;

import java.util.Calendar;

import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Ignore;
import androidx.room.Index;
import androidx.room.PrimaryKey;

import com.example.lib_base.utils.DateConvertUtils;

@Entity(tableName = "history",
        indices = {@Index(value = {"operate_id"}, unique = true)},
        foreignKeys =
                {@ForeignKey(entity = ReagentOperate.class, parentColumns = "id", childColumns = "operate_id", onDelete = ForeignKey.SET_DEFAULT)
                }
)
public class HistoryInfo {
    @PrimaryKey(autoGenerate = true)
    @ColumnInfo(name = "history_id")
    private Long history_id;
    //试剂名
    private String name;
    //试剂批号
    private String batch;
    //库存剩余数量 (批号 + 项目id)的总库存数量
    @ColumnInfo(name = "counts")
    private Long counts = 0L;
    //出入库数
    @ColumnInfo (name = "operator_num")
    private Long num = 0L;

    //试剂信息
    @ColumnInfo(name = "reagents_id")
    private Long reagent_id = 0L;
    //出入库信息
    private Long operate_id = 0L;

    //操作类型
    @ColumnInfo(name = "operate_type")
    private Boolean operateType;

    //操作时间
    private String times;
    //操作数量 减少关联 由于使用了Flow或Livedata监听数据
    // 当两个表都发生变化时监听的数据会多次变化但数据却一模一样 减少计算量提高性能 不过Flow好像高级一些可过滤掉还有些高级特性
    //比如 获取月出库排行时使用Flow就可过滤掉快速刷新表导致出现无用数据  LiveData就不行(暂时不知)
//    @ColumnInfo(name = "operate_num")
//    private Long num;

    @Ignore  //忽略字段
    private Boolean isNew = false;

    public HistoryInfo() {
    }

    public HistoryInfo(String name, String batch, Long counts, Long reagent_id, Long operate_id, Long num,Boolean operate) {
        this.name = name;
        this.batch = batch;
        this.counts = counts;
        this.operateType = operate;
        this.reagent_id = reagent_id;
        this.operate_id = operate_id;
        this.num = num;
        this.times = DateConvertUtils.convertTimeToStringCH(Calendar.getInstance().getTime().getTime(), "yyyy-MM-dd HH:mm:ss");
    }

    public Long getNum() {
        return num;
    }

    public void setNum(Long num) {
        this.num = num;
    }

    public String getTimes() {
        return times;
    }

    public void setTimes(String times) {
        this.times = times;
    }

    public Boolean getNew() {
        return isNew;
    }

    public void setNew(Boolean aNew) {
        isNew = aNew;
    }

    public Long getHistory_id() {
        return history_id;
    }

    public void setHistory_id(Long history_id) {
        this.history_id = history_id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getBatch() {
        return batch;
    }

    public void setBatch(String batch) {
        this.batch = batch;
    }

    public Long getCounts() {
        return counts;
    }

    public void setCounts(Long counts) {
        this.counts = counts;
    }

    public Boolean getOperateType() {
        return operateType;
    }

    public void setOperateType(Boolean operateType) {
        this.operateType = operateType;
    }

    public Long getReagent_id() {
        return reagent_id;
    }

    public void setReagent_id(Long reagent_id) {
        this.reagent_id = reagent_id;
    }

    public Long getOperate_id() {
        return operate_id;
    }

    public void setOperate_id(Long operate_id) {
        this.operate_id = operate_id;
    }
}
